package ddd2;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.Scanner;

public class WordsBuffer {
    public static void main(String[] args) {
        String[] words = {"apple","algorithm","able"};
        Random rand = new Random();
        Scanner sc = new Scanner(System.in);
        LocalDateTime now = LocalDateTime.now();
        int chooseWord = rand.nextInt(words.length);
        char[] ch = words[chooseWord].toCharArray();
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<ch.length;i++){
            move(ch,i,rand.nextInt(ch.length));
        }
        for (int i = 0; i < ch.length; i++) {
            sb.append(ch[i]);
        }
        System.out.println("打乱后的单词为："+ sb +"请输入正确的单词");

        while(true){
            String word = sc.nextLine();
            if(word.equals(words[chooseWord])){
                System.out.println("正确啦！");
                Duration duration = Duration.between(now, LocalDateTime.now());
                System.out.println("用时："+duration.getSeconds()+"秒！");
                break;
            }else{
                System.out.println("错啦");
            }
        }

    }
    public static char[] move(char[] ch, int x, int y) {
        char temp;
        temp = ch[x];
        ch[x] = ch[y];
        ch[y] = temp;
        return ch;
    }
}
